#include "precompiled/pchkrayserkraw.h"
#include "kraw/krawd3d9.h"

#include <d3dx9math.h>

extern LPDIRECT3DDEVICE9 g_pd3d9Device;

//-----------------------------------------------------------------------------

class KrawD3D9View
{
public:

    KrawD3D9View() {}

    D3DXMATRIXA16 matView;
    D3DXMATRIXA16 matProj;
};

//-----------------------------------------------------------------------------

bool KrawD3D9::LoadView( View& view )
{
    if ( view.data ) return false;

    view.data = n_new( KrawD3D9View );

    return true;
}

//-----------------------------------------------------------------------------

void KrawD3D9::UnloadView( View& view )
{
    if ( !view.data ) return;

    n_delete( (KrawD3D9View*) view.data );
}

//-----------------------------------------------------------------------------

void KrawD3D9::DrawView( View& view )
{
    if ( !view.data ) return;

    KrawD3D9View* pD3D9View = (KrawD3D9View*) view.data;
/*
    //setup view matrix
    D3DXVECTOR3* vEyePt = (D3DXVECTOR3*) &view.eye;
    D3DXVECTOR3* vLookatPt = (D3DXVECTOR3*) &view.at;
    D3DXVECTOR3* vUpVec = (D3DXVECTOR3*) &view.up;

    D3DXMatrixLookAtLH( &pD3D9View->matView, vEyePt, vLookatPt, vUpVec );
    g_pd3d9Device->SetTransform( D3DTS_VIEW, &pD3D9View->matView );
*/
    const matrix44& matView = view.transform.getmatrix();
    g_pd3d9Device->SetTransform( D3DTS_VIEW, (D3DMATRIX*) &matView );

    //setup perspective matrix
    D3DXMatrixPerspectiveFovLH( &pD3D9View->matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
    g_pd3d9Device->SetTransform( D3DTS_PROJECTION, &pD3D9View->matProj );
}
